package com.gnkexy.springframework.beans.factory.support;

import com.gnkexy.springframework.beans.factory.DisposableBean;

import java.util.HashMap;
import java.util.Map;

public class DefaultSingletonBeanRegistry implements SingletonBeanRegistry {

    private Map<String,Object> singletonObjects = new HashMap<>();

    private Map<String, DisposableBean> disposableBeans = new HashMap<>();

    protected void registerDisposableBean(String beanName, DisposableBeanAdapter disposableBeanAdapter) {
            disposableBeans.put(beanName,disposableBeanAdapter);
    }


    public Map<String, DisposableBean> getDisposableBeans() {
        return disposableBeans;
    }

    public void setDisposableBeans(Map<String, DisposableBean> disposableBeans) {
        this.disposableBeans = disposableBeans;
    }

    @Override
    public Object getSingleton(String beanName) {
        return singletonObjects.get(beanName);
    }


    public Map<String, Object> getSingletonObjects() {
        return singletonObjects;
    }

    protected void addSingleton(String beanName, Object singletonObject){
        singletonObjects.put(beanName,singletonObject);
    }
}
